/*
 * author      : dormi330
 * date        : 2018/6/26
 * project     : mybatis
 * description : 应用层服务
 */

package com.deep.trade.application;

import com.deep.trade.application.refund.RefundQueryService;
import com.deep.trade.application.refund.RefundService;
import com.deep.trade.common.CommonUtils;
import com.deep.trade.common.TradeException;
import com.deep.trade.domain.refund.RefundOrder;
import com.deep.trade.refund.dto.*;
import com.github.pagehelper.PageInfo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class RefundFacadeImpl {
    private Logger logger = LoggerFactory.getLogger(this.getClass().getName());

    private RefundService refundService;
    private RefundQueryService refundQueryService;

    @Autowired
    public RefundFacadeImpl(
            RefundService refundService
            , RefundQueryService refundQueryService
    ) {
        this.refundService = refundService;
        this.refundQueryService = refundQueryService;
    }

    //========================================== command ==========================================//

    // 添加 refundType
    public void addNewRefundType(InDtoRefundType inDtoRefundType) throws Exception {
        if (null == inDtoRefundType) throw new TradeException("input null");
        refundService.addNewRefundType(inDtoRefundType);
    }

    // 申请退款
    public void applyRefund(InDtoRefundApply inDtoRefundApply) throws Exception {
        refundService.applyRefund(inDtoRefundApply);
    }

    // 进行审核
    public void auditRefundApply(InDtoAuditRefundApply inDtoAuditRefundApply) throws Exception {
        refundService.auditRefundApply(inDtoAuditRefundApply);
    }

    //========================================== query ==========================================//

    public List<OutDtoRefundType> listAllRefundType() throws Exception {
        return refundQueryService.listAllRefundType();
    }

    public PageInfo<OutDtoRefundApply> refundListOfMember(int pageNum, int pageSize) throws Exception {
        PageInfo<RefundOrder> refundApplyPageInfo = refundQueryService.refundListOfMember(pageNum, pageSize);
        return CommonUtils.entity2Dto(refundApplyPageInfo, OutDtoRefundApply.class);
    }

    public PageInfo<OutDtoRefundApply> refundListOfTenant(int pageNum, int pageSize) throws Exception {
        PageInfo<RefundOrder> refundApplyPageInfo = refundQueryService.refundListOfTenant(pageNum, pageSize);
        return CommonUtils.entity2Dto(refundApplyPageInfo, OutDtoRefundApply.class);
    }

    public PageInfo<OutDtoRefundApply> refundListOfSeller(String sellerId, int pageNum, int pageSize) throws Exception {
        PageInfo<RefundOrder> refundApplyPageInfo = refundQueryService.refundListOfSeller(sellerId, pageNum, pageSize);
        return CommonUtils.entity2Dto(refundApplyPageInfo, OutDtoRefundApply.class);
    }
}
